package orthoplanner.com.google.code.tools;

import java.awt.Point;
import java.util.Arrays;

public class AngleTool implements Comparable<AngleTool> {
	private Point[] anglePoints = null, cAnglePoints = null;
	private Point label;

	public Point[] getAnglePoints() {
		return anglePoints;
	}

	public void setAnglePoints(Point[] anglePoints) {
		this.anglePoints = anglePoints;
	}

	public Point[] getcAnglePoints() {
		return cAnglePoints;
	}

	public void setcAnglePoints(Point[] cAnglePoints) {
		this.cAnglePoints = cAnglePoints;
	}

	public AngleTool(Point[] anglePoints, Point[] cAnglePoints, Point label) {
		this.anglePoints = anglePoints;
		this.cAnglePoints = cAnglePoints;
		this.label = label;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + Arrays.hashCode(anglePoints);
		result = prime * result + Arrays.hashCode(cAnglePoints);
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof AngleTool)) {
			return false;
		}
		AngleTool other = (AngleTool) obj;
		if (!checkPoints(anglePoints, other.anglePoints)) {
			return false;
		}
		if (!checkPoints(cAnglePoints, other.cAnglePoints)) {
			return false;
		}
		return true;
	}

	public Point getLabel() {
		return label;
	}

	public void setLabel(Point label) {
		this.label = label;
	}

	public int compareTo(AngleTool o) {
		return this.equals(o) ? 0 : 1;
	}

	private boolean checkPoints(Point[] one, Point[] other) {
		return one[1].equals(other[1])
				&& (one[0].equals(other[0]) || one[0].equals(other[2]))
				&& (one[2].equals(other[0]) || one[2].equals(other[2]));
	}

}
